package org.example.binding;

import org.example.session.SqlSession;

import java.io.Serializable;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class MapperProxy<T> implements InvocationHandler, Serializable {


    private final Class<T> tClass;


    private final SqlSession sqlSession;


    public MapperProxy(Class<T> tClass,SqlSession sqlSession) {
        this.tClass = tClass;
        this.sqlSession = sqlSession;
    }


    @Override
    public Object invoke(Object o, Method method, Object[] objects) throws Throwable {

        String name = tClass.getName();
        String name1 = method.getName();
        String statement = name + "." + name1;
        sqlSession.selectOne(statement,objects);
        return method.invoke(o,objects);
    }
}
